#include "ZLG7289.h"
#include "delay.h"


void ZLG7289_Disp_Init(void)
{
        P4_P7(ZLG7289_CS,0);
        Delay(1);             //delay  25--250us,typical 50us;
        Send8bit(ZLG7289_CMD_RESET);        //zlg7289 reset;
        P4_P7(ZLG7289_CS,1);
}

void ZLG7289_Disp_Num(bit dotOn,uint8 disMode,uint8 disData,uint8 position)
{
        uint16 data sendData = 0;
        uint16 data temp = (uint16)position;
        switch(disMode)
        {
                case 0:  sendData = 0x8000;break;                  //mode 0;mode 0 of the decode;
                case 1:  sendData = 0xc800;break;         //mode 1;mode 1 of the decode;
                case 2:  sendData = 0x9000;break;         //mode 2;no decode;
                default: sendData = 0x9000;break;
        }
        if(dotOn)
                sendData |= 0x0080;         //dot on
        sendData |= disData;
        temp <<= 8;
        sendData |= temp;
        P4_P7(ZLG7289_CS,0);
        Delay(1);            //delay  25--250us,typical 50us;
        Send16bit(sendData);
        P4_P7(ZLG7289_CS,1);
}

void Send8bit(uint8 bit8Temp)
{
	uint8 data temp = bit8Temp;
	uint8 data i;
	ZLG7289_CLK = 0;
        for(i = 0;i < 8;i++)
        {
            if( (temp&0x80) == 0x80)
                    ZLG7289_DIO = 1;
            else
                    ZLG7289_DIO = 0;
        Delay(1);
		ZLG7289_CLK = 1;
        Delay(1);
        ZLG7289_CLK = 0;
		temp = temp<< 1;
		}
}


void Send16bit(uint16 bit16Temp)
{
        uint16 data temp = bit16Temp;
        uint8 data i;
		ZLG7289_CLK = 0;
        for(i = 0;i < 16;i++)
        {
            if((temp&0x8000) == 0x8000)
                ZLG7289_DIO = 1;
            else
            	ZLG7289_DIO = 0;
                
                Delay(1);
                ZLG7289_CLK = 1;
        		Delay(1);
                ZLG7289_CLK = 0;
                temp <<= 1;
        }
}



